package com.xhgj.thread;

/**
 * @author 周宇
 * @create 2020-06-27 23:08
 * 线程礼让，礼让不一定成功，看CPU心情
 */
public class YieldThread {
    public static void main(String[] args) {
        Mythread p = new Mythread();
        new Thread(p, "A").start();
        new Thread(p, "B").start();
    }
}

class Mythread implements Runnable {
    @Override
    public void run() {
        System.out.println(Thread.currentThread().getName() + "--》线程开始执行");
        Thread.yield();//礼让
        System.out.println(Thread.currentThread().getName() + "--》线程停止执行");
    }
}
